home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / IFF / Old_IFF_Packages / July_1992 / modules / loadilbm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-06  |  5.2 KB  |  214 lines

  1. /* loadilbm.c - C. Scheppner CBM
  2.  *
  3.  * High-level ILBM load routines
  4.  *
  5.  * 37.9  04/92 - use vp->ColorMap.Count instead of MAXAMCOLORREG
  6.  * 37.10 07/92 - use scr->RastPort.BitMap instead of &scr->BitMap
  7.  *            for future compatibility
  8.  */
  9. #define INTUI_V36_NAMES_ONLY
  10.  
  11. #include "iffp/ilbm.h"
  12. #include "iffp/ilbmapp.h"
  13.  
  14. extern struct Library *GfxBase;
  15.  
  16. /* loadbrush
  17.  *
  18.  * Passed an initialized ILBMInfo with a not-in-use ParseInfo.iff
  19.  *   IFFHandle and desired propchks, collectchks, and stopchks, and filename,
  20.  *   will load an ILBM as a brush, setting up ilbm->Bmhd, ilbm->camg,
  21.  *   ilbm->brbitmap, ilbm->colortable, and ilbm->ncolors
  22.  *
  23.  *   Note that ncolors may be more colors than you can LoadRGB4.
  24.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if
  25.  *   you change the colors yourself using 1.3/2.0 functions.
  26.  *
  27.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  28.  */
  29.  
  30. LONG loadbrush(struct ILBMInfo *ilbm, UBYTE *filename)
  31. {
  32. LONG error = 0L;
  33.  
  34.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  35.  
  36.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  37.     {
  38.     error = parseifile((struct ParseInfo *)ilbm,
  39.                 ID_FORM, ID_ILBM,
  40.                 ilbm->ParseInfo.propchks,
  41.                 ilbm->ParseInfo.collectchks,
  42.                 ilbm->ParseInfo.stopchks);
  43.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  44.         {
  45.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  46.         {
  47.             if(error = createbrush(ilbm))   deletebrush(ilbm);
  48.         }
  49.         else
  50.         {
  51.         message(SI(MSG_IFFP_NOILBM));
  52.         error = NOFILE;
  53.         }
  54.         }
  55.     if(error)    closeifile((struct ParseInfo *)ilbm);
  56.     }
  57.     return(error);
  58. }
  59.  
  60.  
  61. /* unloadbrush
  62.  *
  63.  * frees and close everything alloc'd/opened by loadbrush
  64.  */
  65. void unloadbrush(struct ILBMInfo *ilbm)
  66. {
  67.     deletebrush(ilbm);
  68.     closeifile((struct ParseInfo *)ilbm);
  69. }
  70.  
  71.  
  72. /* queryilbm
  73.  *
  74.  * Passed an initilized ILBMInfo with a not-in-use IFFHandle,
  75.  *   and a filename,
  76.  *   will open an ILBM, fill in ilbm->camg and ilbm->bmhd,
  77.  *   and close the ILBM.
  78.  *
  79.  * This allows you to determine if the ILBM is a size and
  80.  *   type you want to deal with.
  81.  *
  82.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  83.  */
  84.  
  85. /* query just wants these chunks */
  86. LONG queryprops[] = { ID_ILBM, ID_BMHD,
  87.               ID_ILBM, ID_CAMG,
  88.                       TAG_DONE };
  89.  
  90. /* scan can stop when a CMAP or BODY is reached */
  91. LONG querystops[] = { ID_ILBM, ID_CMAP,
  92.               ID_ILBM, ID_BODY,
  93.               TAG_DONE };
  94.  
  95. LONG queryilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  96. {
  97. LONG error = 0L;
  98. BitMapHeader *bmhd;
  99.  
  100.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  101.  
  102.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  103.     {
  104.     D(bug("queryilbm: openifile successful\n"));
  105.  
  106.     error = parseifile((struct ParseInfo *)ilbm,
  107.             ID_FORM, ID_ILBM,
  108.             queryprops, NULL, querystops);
  109.  
  110.     D(bug("queryilbm: after parseifile, error = %ld\n",error));
  111.  
  112.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  113.         {
  114.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  115.         {
  116.         if(bmhd = (BitMapHeader*)
  117.             findpropdata(ilbm->ParseInfo.iff,ID_ILBM,ID_BMHD))
  118.             {
  119.             *(&ilbm->Bmhd) = *bmhd;
  120.             ilbm->camg = getcamg(ilbm);
  121.             }
  122.         else error = NOFILE;
  123.         }
  124.         else
  125.         {
  126.         message(SI(MSG_IFFP_NOILBM));
  127.         error = NOFILE;
  128.         }
  129.         }
  130.     closeifile(ilbm);
  131.     }
  132.     return(error);
  133. }
  134.  
  135.  
  136. /* loadilbm
  137.  *
  138.  * Passed a not-in-use IFFHandle, an initialized ILBMInfo, and filename,
  139.  *   will load an ILBM into your already opened ilbm->scr, setting up
  140.  *   ilbm->Bmhd, ilbm->camg, ilbm->colortable, and ilbm->ncolors
  141.  *   and loading the colors into the screen's viewport
  142.  *
  143.  *   Note that ncolors may be more colors than you can LoadRGB4.
  144.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if
  145.  *   you change the colors yourself using 1.3/2.0 functions.
  146.  *
  147.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  148.  *
  149.  * NOTE - loadilbm() keeps the IFFHandle open so you can copy
  150.  *   or examine other chunks.  You must call closeifile(iff,ilbm)
  151.  *   to close the file and deallocate the parsed context
  152.  *
  153.  */
  154.  
  155. LONG loadilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  156. {
  157. LONG error = 0L;
  158.  
  159.  
  160.     D(bug("loadilbm:\n"));
  161.  
  162.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  163.     if(!ilbm->scr)        return(CLIENT_ERROR);
  164.  
  165.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  166.     {
  167.     D(bug("loadilbm: openifile successful\n"));
  168.  
  169.     error = parseifile((struct ParseInfo *)ilbm,
  170.             ID_FORM, ID_ILBM,
  171.             ilbm->ParseInfo.propchks,
  172.             ilbm->ParseInfo.collectchks,
  173.             ilbm->ParseInfo.stopchks);
  174.  
  175.     D(bug("loadilbm: after parseifile, error = %ld\n",error));
  176.  
  177.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  178.         {
  179.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  180.         {
  181.             error = loadbody(ilbm->ParseInfo.iff,
  182.                 ilbm->scr->RastPort.BitMap, &ilbm->Bmhd);
  183.  
  184.         D(bug("loadilbm: after loadbody, error = %ld\n",error));
  185.  
  186.         if(!error)
  187.             {
  188.             if(!(getcolors(ilbm)))
  189.                 LoadRGB4(&ilbm->scr->ViewPort,ilbm->colortable,
  190.             MIN(ilbm->ncolors,ilbm->scr->ViewPort.ColorMap->Count));
  191.             } 
  192.         }
  193.         else
  194.         {
  195.         message(SI(MSG_IFFP_NOILBM));
  196.         error = NOFILE;
  197.         }
  198.         }
  199.     if(error)    closeifile((struct ParseInfo *)ilbm);
  200.     }
  201.     return(error);
  202. }
  203.  
  204.  
  205. /* unloadilbm
  206.  *
  207.  * frees and closes everything allocated by loadilbm
  208.  */
  209. void unloadilbm(struct ILBMInfo *ilbm)
  210. {
  211.     closeifile((struct ParseInfo *)ilbm);
  212.     freecolors(ilbm);
  213. }
  214.